import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { HttpExceptionFilter } from './filters/http-exception/http-exception.filter';
import { TransformInterceptor } from './interceptor/transform.interceptor';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    app.enableCors();
    app.useGlobalFilters(new HttpExceptionFilter());
    app.useGlobalInterceptors(new TransformInterceptor());
    const config = new DocumentBuilder()
        .setTitle('名称')
        .setDescription(
            '描述：<a href="http://localhost:3000/api-json">默认 json 链接</a>',
        )
        .setVersion('1.0.1')
        .setOpenAPIVersion('3.1.0')
        // 添加标签
        .addTag('users')
        .addTag('app')
        // 添加授权
        .addBearerAuth()
        .build();
    // 创建文档
    const document = SwaggerModule.createDocument(app, config);
    // 设置文档路径 为 api
    SwaggerModule.setup('api', app, document);

    app.listen(process.env.PORT ?? 3000);

    console.log(`服务器运行在: http://localhost:${3000}`);
}
bootstrap();
